package logic

import (
	"context"
	"fmt"
	"store/model/mysql"

	"store/userrpc/internal/svc"
	"store/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *userrpc.AddRequest) (*userrpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	var store = mysql.Store{
		Name: in.Name,
		Addr: in.Addr,
		Tel:  in.Tel,
	}
	err := mysql.DB.Debug().Create(&store).Error
	if err != nil {
		return nil, fmt.Errorf("添加店铺失败")
	}
	return &userrpc.AddResponse{Id: int64(store.ID)}, nil
}
